//
//  BluetoothManager.h
//  Saas
//
//  Created by 杨荣 on 2020/6/1.
//  Copyright © 2020 bing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

NS_ASSUME_NONNULL_BEGIN

@interface BluetoothManager : NSObject

+ (instancetype)sharedInstance;


/* 扫描 */
typedef void (^ScanSuccess)(NSArray <CBPeripheral *>*peripheralArray);
typedef void (^ScanFailure)(CBCentralManagerState state,NSString *stateMessage);
- (void)scanWithSuccess:(ScanSuccess)scanSuccess failure:(ScanFailure)scanFailure;
/* 停止扫描 */
- (void)stopScan;


/* 连接 */
typedef void (^DidConnectPeripheral)(CBPeripheral *peripheral);
typedef void (^DidFailToConnectPeripheral)(CBPeripheral *peripheral,NSError *error);
typedef void (^DidDisconnectPeripheral)(CBPeripheral *peripheral,NSError *error);
- (void)connect:(CBPeripheral *)peripheral didConnectPeripheral:(DidConnectPeripheral)didConnectPeripheral didFailToConnectPeripheral:(DidFailToConnectPeripheral)didFailToConnectPeripheral didDisconnectPeripheral:(DidDisconnectPeripheral)didDisconnectPeripheral;
/* 取消连接 */
- (void)cancelConnect;





/* 写入 */
typedef void (^WriteToPeripheralSuccess)(void);
typedef void (^WriteToPeripheralFailure)(NSString *errorMessage);
- (void)writeToPeripheralWithData:(NSData *)data success:(WriteToPeripheralSuccess)success failure:(WriteToPeripheralFailure)failure;


/* 接收 */
typedef void (^DidReceiveDataFromPeripheral)(NSString *string);
- (void)didReceiveDataFromPeripheral:(DidReceiveDataFromPeripheral)didReceiveDataFromPeripheral;

@end

NS_ASSUME_NONNULL_END
